<?php
require_once('../../system/file_model.php'); 
require_once('../config.php');
if(isset($_POST['submit'])){
    if ($_FILES["file"]["error"] <= 0){
		$file->upload_file($_FILES['file']['name'],$_FILES['file']['tmp_name']);
		
		//保存到数据库里		
		$db_file->query("INSERT INTO file ( type, size,level, name, links) 
		  VALUES( '".$_FILES["file"]["type"]."', 
		   '".($_FILES["file"]["size"] / 1024)."',
		    '".$_POST['selected']."',
			'".$_FILES["file"]["name"]."',
			 '"."../ui/upload/".$_FILES["file"]["name"]."')");
			 
		//检查
	    $query_flie = $db_file->query("SELECT * FROM file WHERE name = '".$_FILES["file"]["name"]."'");
	    $file_num   = $db_file->fetch_array($query_flie);
	    if(!empty($file_num)){
			echo "<script>alert('上传成功！');</script>";  
	    }else{
			echo "<script>alert('上传失败！'); </script>";
			//删除文件
			unlink("upload/".$_FILES["file"]["name"]);
	    }
		
	    //添加痕迹
		 $sql="INSERT INTO history ( time, operate) VALUES ( now(), '创建')";
		 $db_file->query( $sql);
		 
	}else{
		echo  '上传错误代码：'.$_FILES["file"]["error"]."<br>";
	}
}

?>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit" value="上传文件" />
</form>
